"""
输入任意整数，
若为奇数则乘三加一（*3+1），
若为偶数则除二（/2）知道输出结果为1，统计变换消耗的次数和过程
"""


def cat(n):
    if n <= 0:
        return "请输入一个正整数"

    count = 0
    sequence = [n]

    while n != 1:
        if n % 2 == 0:  # 偶数
            n //= 2
        else:  # 奇数
            n = n * 3 + 1
        sequence.append(n)
        count += 1

    return count, sequence


try:
    number = int(input("请输入一个正整数："))
    steps, process = cat(number)
    print(f"变换消耗的次数: {steps}")
    print(f"变换过程: {process}")
except ValueError:
    print("输入无效，请输入一个整数。")